From 929d325560a206e78d1c4afba5ae3b22605ea954 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 29 Jan 2020 16:55:44 +0100 Subject: [PATCH] profiler: Exit gracefully on SIGTERM This is nice, since it lets me quickly launch a test app and terminate it with Ctrl-C and still produce a usable sysprof trace. --- gdk/gdkprofiler.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gdk/gdkprofiler.c b/gdk/gdkprofiler.c index 93055ac9a8..5b4e976110 100644 --- a/gdk/gdkprofiler.c +++ b/gdk/gdkprofiler.c @@ -21,6 +21,7 @@ #include "config.h" #include +#include #ifdef HAVE_UNISTD_H #include @@ -38,7 +39,7 @@ static SysprofCaptureWriter *writer = NULL; static gboolean running = FALSE; static void -profiler_stop (void) +profiler_stop (int s) { if (writer) sysprof_capture_writer_unref (writer); @@ -67,7 +68,8 @@ gdk_profiler_start (int fd) if (writer) running = TRUE; - atexit (profiler_stop); + atexit (G_CALLBACK (profiler_stop)); + signal (SIGTERM, profiler_stop); } void -- 2.30.2